/**
 * 修改了缩放默认
 * Button 增加了音效
 * ZhuangZhuang
 */


const SOUND_TYPE = cc.Enum({
    NORMAL: 0,
    CLICK: 1, 
});

let ButtonEx = cc.Class({
    extends: cc.Button,   
   
    properties: { 
        Sound:{
            default:SOUND_TYPE.CLICK,
            type:cc.Enum(SOUND_TYPE)
        }, 
        zoomScale: {
            default: 0.9,
            tooltip: CC_DEV && 'i18n:COMPONENT.button.zoom_scale',
            override:true,
        }, //默认缩放比
        transition: {
            override:true,
            default: cc.Button.Transition.SCALE,
            tooltip: CC_DEV && 'i18n:COMPONENT.button.transition',
            type:  cc.Button.Transition,
            animatable: false,
            notify (oldValue) {
                this._updateTransition(oldValue);
            },
            formerlySerializedAs: 'transition', 
        }
    },
    start(){
       this.node.on(cc.Node.EventType.TOUCH_START, this.onButtonTouched, this);  
    }, 
    onButtonTouched(){ 
        if(this.Sound == SOUND_TYPE.NORMAL) return true;
        //todo 自己实现的通过点击
        //Tools.playEffect("Audio/UIClick",false)
    },
});
 
cc.Class.Attr.setClassAttr(ButtonEx, 'normalColor', 'visible', function() {
    return this.transition === cc.Button.Transition.COLOR;
});
cc.Class.Attr.setClassAttr(ButtonEx, 'pressedColor', 'visible', function() {
    return this.transition === cc.Button.Transition.COLOR;
});
cc.Class.Attr.setClassAttr(ButtonEx, 'hoverColor', 'visible', function() {
    return this.transition === cc.Button.Transition.COLOR;
});
cc.Class.Attr.setClassAttr(ButtonEx, 'disabledColor', 'visible', function() {
    return this.transition  === cc.Button.Transition.COLOR;
});
cc.Class.Attr.setClassAttr(ButtonEx, 'duration', 'visible', function() {
    return this.transition === cc.Button.Transition.COLOR || this.transition === cc.Button.Transition.SPRITE || this.transition ===cc.Button.Transition.SCALE;
}); 
cc.Class.Attr.setClassAttr(ButtonEx, 'normalSprite', 'visible', function() {
    return this.transition === cc.Button.Transition.SPRITE;
});
cc.Class.Attr.setClassAttr(ButtonEx, 'pressedSprite', 'visible', function() {
    return this.transition === cc.Button.Transition.SPRITE;
});
cc.Class.Attr.setClassAttr(ButtonEx, 'hoverSprite', 'visible', function() {
    return this.transition ===cc.Button.Transition.SPRITE;
});
cc.Class.Attr.setClassAttr(ButtonEx, 'disabledSprite', 'visible', function() {
    return this.transition  === cc.Button.Transition.SPRITE;
}); 
cc.Class.Attr.setClassAttr(ButtonEx, 'zoomScale', 'visible', function() {  
    return this.transition  === cc.Button.Transition.SCALE;
});
cc.Class.Attr.setClassAttr(ButtonEx, 'normalMaterial', 'visible', function() {
    return this.enableAutoGrayEffect === true;
});
cc.Class.Attr.setClassAttr(ButtonEx, 'grayMaterial', 'visible', function() {
    return this.enableAutoGrayEffect === true;
});

